package com.baymax.test.scene.view

import android.content.Context
import android.opengl.GLES20
import android.opengl.GLSurfaceView
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class TestGLSurfaceView : GLSurfaceView {
    constructor(context: Context?) : super(context)

    private val renderer = object: Renderer{
        override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
            val version = GLES20.glGetString(GLES20.GL_VERSION)
           println("onSurfaceCreated $gl ,$config ,version $version")
            GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f)
        }

        override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
            println("onSurfaceCreated $gl ,$width ,$height")
            GLES20.glViewport(0, 0, width, height)
        }

        override fun onDrawFrame(gl: GL10?) {
            println("onDrawFrame $gl ")
            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
        }
    }
    init {
        // Create an OpenGL ES 2.0 context
        setEGLContextClientVersion(2)
        // Set the Renderer for drawing on the GLSurfaceView
        setRenderer(renderer)
        // Render the view only when there is a change in the drawing data
        renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY;
    }
}